﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.IO;
using IniParser;
using IniParser.Helpers;
using IniParser.Exceptions;
using IniParser.Model;
using IniParser.Parser;
using Syringe;
using Syringe.Win32;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;

namespace DotaHelperConfigurator
{
    public partial class Form1 : Form
    {
        
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;

        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();

        private void MMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        const int WM_NCHITTEST = 0x0084;
        const int HTCAPTION = 2;
        private const int HTCLIENT = 0x1;
        const int HTCLOSE = 20;
        static Injector syringe;
        static string war3path;
        static Bitmap MiniMap;
        static string _status_string = "NONE";

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_NCHITTEST)
            {
                base.WndProc(ref m);
                if (m.Result != (IntPtr)HTCLOSE)
                    m.Result = (IntPtr)HTCAPTION;
                return;
            }
            if ((m.Msg == (int)0x0112 && m.WParam == (IntPtr)0xF122) ||
                (m.Msg == (int)0x0112 && m.WParam == (IntPtr)0xF032))
            {
                m.Msg = 0x0;
            }
            base.WndProc(ref m);
        }
        string CutMe(string str, int how)
        {
            if (str.Length > how)
            {
                str = str.Substring(0, how);
                if (str.LastIndexOf(' ') > 0)
                {
                    str = str.Substring(0, str.LastIndexOf(' ')) + " ...";
                }
            }
            return str;
        }
        private static FileIniDataParser DotaHelper;
        private static IniData DotaHelperData;
        private static ToolTip toolTip1;
        public Form1()
        {

            InitializeComponent();

        }

        public string EncodeToDef(string text)
        {
            byte[] myASCIIBytes = Encoding.UTF8.GetBytes(text);
            byte[] myUTF8Bytes = Encoding.Convert(Encoding.UTF8, Encoding.Default, myASCIIBytes);
            return Encoding.UTF8.GetString(myUTF8Bytes);
        }
        public string EncodeToUndef(string text)
        {
            byte[] myASCIIBytes = Encoding.Default.GetBytes(text);
            byte[] myUTF8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, myASCIIBytes);
            return Encoding.Default.GetString(myUTF8Bytes);
        }
        private void label1_DragLeave(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox2.Text = EncodeToDef(DotaHelperData["STRING"][comboBox1.Text]);
            comboBox1.Visible = false;
            textBox2.Location = new Point(128, 123); //204 default
            textBox2.Size = new Size(156, 22); //204 default
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DotaHelper = new FileIniDataParser();
            DotaHelperData = DotaHelper.ReadFile("DotaHelper.ini", Encoding.Default);
            _status_string = _status.Text;
            this.Width = 340;
            MiniMap = new Bitmap(MinimapPan1.BackgroundImage,MinimapPan1.BackgroundImage.Width,MinimapPan1.BackgroundImage.Height);
            Boolean SSREENABLED = false;
            Boolean.TryParse(DotaHelperData["FEATURES"]["SSRE"], out SSREENABLED);
            Boolean SKILLENABLED = false;
            Boolean.TryParse(DotaHelperData["FEATURES"]["SKILL"], out SKILLENABLED);
            Boolean ENEMYENABLED = false;
            Boolean.TryParse(DotaHelperData["FEATURES"]["ENEMY"], out ENEMYENABLED);
            Boolean CHECKVISENABLED = false;
            Boolean.TryParse(DotaHelperData["FEATURES"]["CHECKVIS"], out CHECKVISENABLED);
            Boolean CheckMoneyENABLED = false;
            Boolean.TryParse(DotaHelperData["FEATURES"]["CheckMoney"], out CheckMoneyENABLED);
            Boolean SSRECHAT = false;
            Boolean.TryParse(DotaHelperData["ALLCHAT"]["SSRE"], out SSRECHAT);
            Boolean SKILLCHAT = false;
            Boolean.TryParse(DotaHelperData["ALLCHAT"]["SKILL"], out SKILLCHAT);
            Boolean ENEMYCHAT = false;
            Boolean.TryParse(DotaHelperData["ALLCHAT"]["ENEMY"], out ENEMYCHAT);
            float EnemyRad = 3000f;
            var us_EN = new CultureInfo("en-US");
            EnemyRad = float.Parse(DotaHelperData["SET"]["EnemyDetect"], us_EN);
            
            SSRE1.Checked = SSREENABLED;
            Skills1.Checked = SKILLENABLED;
            DEnemy1.Checked = ENEMYENABLED;

            inchat1.Checked = SSRECHAT;
            inchat2.Checked = SKILLCHAT;
            inchat3.Checked = ENEMYCHAT;

            NotifyE1.Checked = CHECKVISENABLED;
            Guesss1.Checked = CheckMoneyENABLED;

            distance1.Text = EnemyRad.ToString().Replace(',','.');

            distance1.Visible = DEnemy1.Checked;


            toolTip1 = new ToolTip();
            toolTip1.AutoPopDelay = 5000;
            toolTip1.InitialDelay = 550;
            toolTip1.ReshowDelay = 500;
            toolTip1.ShowAlways = true;
            toolTip1.SetToolTip(this.UpdateCFG1, "Обновить настройки. (Только после загрузки DotaHelper)");
            toolTip1.SetToolTip(this.InjectDll1, "Загрузить DotaHelper(или другой хак)");
            toolTip1.SetToolTip(this.ForceStart1, "Нажмите сюда если хак не запустился, а игра началась.");
            toolTip1.SetToolTip(this.SSRE1, "Актвивировать предупреждение о приходе/уходе противника с лайна.");
            toolTip1.SetToolTip(this.DEnemy1, "Активировать предупреждение о приближении противника.");
            toolTip1.SetToolTip(this.Skills1, "Активировать предупреждение о использовании некоторых скилов.");
            toolTip1.SetToolTip(this.inchat1, "Писать в чат.");
            toolTip1.SetToolTip(this.inchat2, "Писать в чат.");
            toolTip1.SetToolTip(this.inchat3, "Писать в чат.");
            toolTip1.SetToolTip(this.NotifyE1, "Активировать предупреждении о видимости для противника.");
            toolTip1.SetToolTip(this.Guesss1, "Предупреждать о покупке некоторых предметов..");
            toolTip1.SetToolTip(this.AllWrd1, "Показать варды на миникарте.");
            toolTip1.SetToolTip(this.MinesL1, "Показать мины на миникарте.");
            toolTip1.SetToolTip(this.Herolist1, "Показать героев на миникарте.");
            toolTip1.SetToolTip(this.UnilogB1, "Создать список юнитов в папке с варкрафтом.");
            toolTip1.SetToolTip(this.ClearBtn1, "Очистить миникарту.");
            toolTip1.SetToolTip(this.MinimapPan1, "Это миникарта. This is the minimap.");
            toolTip1.SetToolTip(this.Unloader, "Попытаться прервать работу хака.");

            string[] filescfg = Directory.GetFiles("DHLangConfig");
            string[] fileshelp = Directory.GetFiles("Lang");

            for(int i = 0; i < filescfg.Length;i++)
            {
                
                for (int n = 0; n < fileshelp.Length;n++)
                {
                    if (Path.GetFileName(filescfg[i]) == Path.GetFileName(fileshelp[n]))
                    {
                        //MessageBox.Show("A");
                      /*  if (File.Exists("dotahelper.cfg.bak"))
                        {
                            File.Delete("dotahelper.cfg.bak");
                        }
                        if (File.Exists("dotahelper.ini"))
                        {
                            File.Move("dotahelper.ini", "dotahelper.cfg.bak");
                        }
                        if (File.Exists(@"DHLangConfig\"+fileshelp[n]))
                        {
                            File.Move(@"DHLangConfig\" + fileshelp[n], "dotahelper.ini");
                        }*/
                        FileIniDataParser HelperLang = new FileIniDataParser();;
                        IniData HelperLangData = HelperLang.ReadFile(filescfg[n], Encoding.Default);
                        
                        string tmpstring = EncodeToDef(HelperLangData["LANG"]["Lang"]);
                        LangList.Items.Add(tmpstring);
                    }
                }
            }

            LangSelect(null, null);

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["FEATURES"]["SSRE"] = SSRE1.Checked.ToString();
            inchat1.Visible = SSRE1.Checked;
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["FEATURES"]["SKILL"] = Skills1.Checked.ToString();
            inchat2.Visible = Skills1.Checked;
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["FEATURES"]["ENEMY"] = DEnemy1.Checked.ToString();
            inchat3.Visible = DEnemy1.Checked;
            distance1.Visible = DEnemy1.Checked;
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["ALLCHAT"]["SSRE"] = inchat1.Checked.ToString();
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["ALLCHAT"]["SKILL"] = inchat2.Checked.ToString();
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["ALLCHAT"]["ENEMY"] = inchat3.Checked.ToString();
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void checkBox7_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["FEATURES"]["CHECKVIS"] = NotifyE1.Checked.ToString();
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void checkBox8_CheckedChanged(object sender, EventArgs e)
        {
            DotaHelperData["FEATURES"]["CheckMoney"] = Guesss1.Checked.ToString();
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }
        private void button7_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void _gogame_Click(object sender, EventArgs e)
        {
            comboBox1.Visible = true;
            textBox2.Location = new Point(204, 123); //204 Normatl
            textBox2.Size = new Size(80, 22); //204 Normatl
            DotaHelperData["STRING"][comboBox1.Text] = EncodeToUndef(textBox2.Text);
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
            _status.Text = "Save " + comboBox1.Text + " like " + CutMe(textBox2.Text,25);
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) {
                this.Text = "SAVED";
                float tmpfloat = 3000f;
                float.TryParse(distance1.Text, out tmpfloat);
                DotaHelperData["SET"]["EnemyDetect"] = tmpfloat.ToString();
                DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
                distance1.Visible = false;
                _status.Text = "Save 'SeeMe' like a " + tmpfloat.ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //button4.Visible = true;
            if (Process.GetProcessesByName(textBox4.Text).Length > 0)
            {
                syringe = new Injector(Process.GetProcessesByName(textBox4.Text)[0]);
                war3path = Path.GetDirectoryName(Process.GetProcessesByName(textBox4.Text)[0].Modules[0].FileName);
                // MessageBox.Show(Path.GetDirectoryName(Process.GetProcessesByName(textBox4.Text)[0].Modules[0].FileName));
                if (File.Exists(war3path + "\\dotahelper.ini"))
                {
                    File.Delete(war3path + "\\dotahelper.ini");
                    File.Copy("DotaHelper.ini", war3path + "\\dotahelper.ini", true);
                }
                else File.Copy("DotaHelper.ini", war3path + "\\dotahelper.ini", true);
                syringe.EjectOnDispose = false;
                // syringe.EjectLibrary(textBox3.Text);
                syringe.InjectLibrary(textBox3.Text);
                //syringe.Dispose();
                //syringe.CallExport(textBox3.Text, "ForceInitialize");
                ExtraFeat.Visible = true;

            }
            else MessageBox.Show("Не найден процесс.", "Ошибка.");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (Process.GetProcessesByName(textBox4.Text).Length > 0)
            {
               // syringe = new Injector(Process.GetProcessesByName(textBox4.Text)[0]);
             //   syringe.EjectOnDispose = false;
              //  syringe.EjectLibrary(textBox3.Text);
                if (File.Exists(war3path + "\\dotahelper.ini"))
                {
                    File.Delete(war3path + "\\dotahelper.ini");
                    File.Copy("DotaHelper.ini", war3path + "\\dotahelper.ini", true);
                }
                else File.Copy("DotaHelper.ini", war3path + "\\dotahelper.ini", true);
               // syringe.InjectLibrary(textBox3.Text);
                syringe.CallExport(textBox3.Text, "UpdateCFG");
            }
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                comboBox1.Visible = true;
                textBox2.Location = new Point(204, 123); //204 Normatl
                textBox2.Size = new Size(80, 22); //204 Normatl
                DotaHelperData["STRING"][comboBox1.Text] = textBox2.Text;
                DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
                _status.Text = "Save " + comboBox1.Text + " like " + CutMe(textBox2.Text, 25);
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            var us_EN = new CultureInfo("en-US");
            float tmpfloat = 3000.1f;
            tmpfloat = float.Parse(distance1.Text, us_EN); 
            DotaHelperData["SET"]["EnemyDetect"] = tmpfloat.ToString().Replace(',','.');
            DotaHelper.SaveFile("DotaHelper.ini", DotaHelperData, Encoding.Default);
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
          DialogResult result1 = MessageBox.Show("Нажимать \"OK\" только в игре если DotaHelper не запустился \n И ОБЯЗАТЕЛЬНО ЗАКРОЙТЕ War3 ПОСЛЕ ИГРЫ \n Иначе ВАС выкинет в следующей игре! \n Нажмите \"OK\" если уверены что нет другого выхода.",
         "ВНИМАНИЕ!!!",
         MessageBoxButtons.YesNo);
            if (result1 == DialogResult.Yes)
            {
                MessageBox.Show("Будет принудительно запущен хак. \nОбязательно перезапустите варкрафт после этой игры!", "Предупреждение:");
                syringe.CallExport(textBox3.Text, "ForceStart");
            }
        }

        private void Features(object sender, EventArgs e)
        {
            this.Width = 728;
        }

        private void WardList(object sender, EventArgs e)
        {
            if (File.Exists(war3path + "\\wardlist.log"))
                File.Delete(war3path + "\\wardlist.log");

            syringe.CallExport(textBox3.Text, "GetWardList");

            int checklag = 10;
            while (!File.Exists(war3path + "\\wardlist.log") && checklag > 0) { checklag--; System.Threading.Thread.Sleep(1000); };
            System.Threading.Thread.Sleep(50);

            if (checklag == 0)
                MessageBox.Show("Данные не получены! Возможно вы используете старую версию DotaHelper.", "ОШИБКА!!");
            else
            {
                string regex = @"^\ *X\:([\-\.0-9]*)\ *Y\:([\-\.0-9]*)\ *$";
                if (File.Exists("wardlist.log"))
                    File.Delete("wardlist.log");

                File.Copy(war3path + "\\wardlist.log", "wardlist.log");
                string[] crdlist = File.ReadAllLines("wardlist.log");

                Regex re = new Regex(regex, RegexOptions.Compiled);
                var us_EN = new CultureInfo("en-US");
                using (var bitmap = new Bitmap(MiniMap, MiniMap.Width, MiniMap.Height))
                {
                    foreach (var line in crdlist)
                    {
                        Match m = re.Match(line);
                        if (m.Success)
                        {
                            String sX = m.Groups[1].Value;
                            String sY = m.Groups[2].Value;

                            double fX = float.Parse(sX, us_EN) + 7250.0d;
                            double fY = float.Parse(sY, us_EN) + 7950.0d;

                            double fMX = Convert.ToDouble(bitmap.Width) / 14944.0d;
                            double fMY = Convert.ToDouble(bitmap.Height) / 15248.0d;

                            int X = Convert.ToInt32(fMX * fX);
                            int Y = bitmap.Height - Convert.ToInt32(fMY * fY);

                            if (X < 1)
                                X = 1;
                            if (Y < 1)
                                Y = 1;
                            if (Y + 1 > bitmap.Height)
                                Y = bitmap.Height;
                            if (X + 1 > bitmap.Width)
                                X = bitmap.Width;

                            bitmap.SetPixel(X, Y, Color.White);
                            bitmap.SetPixel(X + 1, Y, Color.White);
                            bitmap.SetPixel(X, Y + 1, Color.White);
                            bitmap.SetPixel(X + 1, Y + 1, Color.White);
                            bitmap.SetPixel(X - 1, Y, Color.White);
                            bitmap.SetPixel(X, Y - 1, Color.White);
                            bitmap.SetPixel(X - 1, Y - 1, Color.White);
                        }
                    }
                    MinimapPan1.BackgroundImage = new Bitmap(bitmap, bitmap.Width, bitmap.Height);
                }
                if (File.Exists(war3path + "\\wardlist.log"))
                    File.Delete(war3path + "\\wardlist.log");

                if (File.Exists("wardlist.log"))
                    File.Delete("wardlist.log");

            }
        }

        private void MinList(object sender, EventArgs e)
        {
            if (File.Exists(war3path + "\\minelist.log"))
                File.Delete(war3path + "\\minelist.log");

            syringe.CallExport(textBox3.Text, "GetMinList");

            int checklag = 10;
            while (!File.Exists(war3path + "\\minelist.log") && checklag > 0) { checklag--; System.Threading.Thread.Sleep(1000); };
            System.Threading.Thread.Sleep(50);

            if (checklag == 0)
                MessageBox.Show("Данные не получены! Возможно вы используете старую версию DotaHelper.", "ОШИБКА!!");
            else
            {
                string regex = @"^\ *X\:([\-\.0-9]*)\ *Y\:([\-\.0-9]*)\ *$";
                if (File.Exists("minelist.log"))
                    File.Delete("minelist.log");

                File.Copy(war3path + "\\minelist.log", "minelist.log");
                string[] crdlist = File.ReadAllLines("minelist.log");

                Regex re = new Regex(regex, RegexOptions.Compiled);
                var us_EN = new CultureInfo("en-US");
                using (var bitmap = new Bitmap(MiniMap,MiniMap.Width,MiniMap.Height))
                {
                    foreach (var line in crdlist)
                    {
                        Match m = re.Match(line);
                        if (m.Success)
                        {
                            String sX = m.Groups[1].Value;
                            String sY = m.Groups[2].Value;

                            double fX = float.Parse(sX, us_EN) + 7250.0d;
                            double fY = float.Parse(sY, us_EN) + 7950.0d;

                            double fMX = Convert.ToDouble(bitmap.Width) / 14944.0d;
                            double fMY = Convert.ToDouble(bitmap.Height) / 15248.0d;

                            int X = Convert.ToInt32(fMX * fX);
                            int Y = bitmap.Height - Convert.ToInt32(fMY * fY);

                            if (X < 1)
                                X = 1;
                            if (Y < 1)
                                Y = 1;
                            if (Y + 1 > bitmap.Height)
                                Y = bitmap.Height;
                            if (X + 1 > bitmap.Width)
                                X = bitmap.Width;

                            bitmap.SetPixel(X, Y, Color.White);
                            bitmap.SetPixel(X + 1, Y, Color.White);
                            bitmap.SetPixel(X, Y + 1, Color.White);
                            bitmap.SetPixel(X + 1, Y + 1, Color.White);
                            bitmap.SetPixel(X - 1, Y, Color.White);
                            bitmap.SetPixel(X, Y - 1, Color.White);
                            bitmap.SetPixel(X - 1, Y - 1, Color.White);
                        }
                    }
                    MinimapPan1.BackgroundImage = new Bitmap(bitmap,bitmap.Width,bitmap.Height);
                }
                if (File.Exists(war3path + "\\minelist.log"))
                    File.Delete(war3path + "\\minelist.log");

                if (File.Exists("minelist.log"))
                    File.Delete("minelist.log");

            }

        }

        private void HeroPos(object sender, EventArgs e)
        {
            if (File.Exists(war3path + "\\herolist.log"))
                File.Delete(war3path + "\\herolist.log");

            syringe.CallExport(textBox3.Text, "GetHeroList");

            int checklag = 10;
            while (!File.Exists(war3path + "\\herolist.log") && checklag > 0) { checklag--; System.Threading.Thread.Sleep(1000); };
            System.Threading.Thread.Sleep(50);

            if (checklag == 0)
                MessageBox.Show("Данные не получены! Возможно вы используете старую версию DotaHelper.", "ОШИБКА!!");
            else
            {
                string regex = @"^\ *X\:([\-\.0-9]*)\ *Y\:([\-\.0-9]*)\ *$";
                if (File.Exists("herolist.log"))
                    File.Delete("herolist.log");

                File.Copy(war3path + "\\herolist.log", "herolist.log");
                string[] crdlist = File.ReadAllLines("herolist.log");

                Regex re = new Regex(regex, RegexOptions.Compiled);
                var us_EN = new CultureInfo("en-US");
                using (var bitmap = new Bitmap(MiniMap, MiniMap.Width, MiniMap.Height))
                {
                    foreach (var line in crdlist)
                    {
                        Match m = re.Match(line);
                        if (m.Success)
                        {
                            String sX = m.Groups[1].Value;
                            String sY = m.Groups[2].Value;

                            double fX = float.Parse(sX, us_EN) + 7250.0d;
                            double fY = float.Parse(sY, us_EN) + 7950.0d;

                            double fMX = Convert.ToDouble(bitmap.Width) / 14944.0d;
                            double fMY = Convert.ToDouble(bitmap.Height) / 15248.0d;

                           // MessageBox.Show(float.Parse(sX, us_EN).ToString(), float.Parse(sY, us_EN).ToString());

                            int X = Convert.ToInt32(fMX * fX);
                            int Y = bitmap.Height - Convert.ToInt32(fMY * fY);

                            if (X < 2)
                                X = 2;
                            if (Y < 2)
                                Y = 2;
                            if (Y + 2 > bitmap.Height)
                                Y = bitmap.Height-1;
                            if (X + 2 > bitmap.Width)
                                X = bitmap.Width-1;

                            bitmap.SetPixel(X, Y, Color.Red);
                            bitmap.SetPixel(X + 1, Y, Color.White);
                            bitmap.SetPixel(X, Y + 1, Color.White);
                            bitmap.SetPixel(X + 1, Y + 1, Color.White);
                            bitmap.SetPixel(X - 1, Y, Color.White);
                            bitmap.SetPixel(X, Y - 1, Color.White);
                            bitmap.SetPixel(X - 1, Y - 1, Color.White);
                            bitmap.SetPixel(X + 2, Y, Color.White);
                            bitmap.SetPixel(X, Y + 2, Color.White);
                            bitmap.SetPixel(X + 2, Y + 2, Color.White);
                            bitmap.SetPixel(X - 2, Y, Color.White);
                            bitmap.SetPixel(X, Y - 2, Color.White);
                            bitmap.SetPixel(X - 2, Y - 2, Color.White);
                        }
                    }
                    MinimapPan1.BackgroundImage = new Bitmap(bitmap, bitmap.Width, bitmap.Height);
                }
                if (File.Exists(war3path + "\\herolist.log"))
                    File.Delete(war3path + "\\herolist.log");

                if (File.Exists("herolist.log"))
                    File.Delete("herolist.log");

            }
        }

        private void Free(object sender, EventArgs e)
        {
            MinimapPan1.BackgroundImage = MiniMap;
        }

        private void CreateUnitLog(object sender, EventArgs e)
        {
            syringe.CallExport(textBox3.Text, "CreateLog");
        }

        private void _status_Click(object sender, EventArgs e)
        {
            Process.Start("http://d3scene.ru");
            System.Threading.Thread.Sleep(100);
            Process.Start("http://zhyk.ru");
        }
        
        private void _status_MouseEnter(object sender, EventArgs e)
        {
            _status_string = _status.Text;
            _status.Text = "Abso! for d3scene.ru!    And special thanks to: Der_SySLIK";
        }

        private void _status_MouseLeave(object sender, EventArgs e)
        {
            _status.Text = _status_string;
        }

        private void PleaseReaload(object sender, EventArgs e)
        {
            Form1_Load(null, null);
        }

        private void UnloadDll(object sender, EventArgs e)
        {
            syringe.CallExport(textBox3.Text, "ForceUnload");
            syringe.EjectLibrary(textBox3.Text);
        }

        private void LangSelect(object sender, EventArgs e)
        {
            string[] filescfg = Directory.GetFiles("DHLangConfig");
            string[] fileshelp = Directory.GetFiles("Lang");

            for (int i = 0; i < filescfg.Length; i++)
            {

                for (int n = 0; n < fileshelp.Length; n++)
                {
                    if (Path.GetFileName(filescfg[i]) == Path.GetFileName(fileshelp[n]))
                    {
                        //MessageBox.Show("A");
                        /* */
                        FileIniDataParser HelperLang = new FileIniDataParser(); ;
                        IniData HelperLangData = HelperLang.ReadFile(filescfg[n], Encoding.Default);

                        string tmpstring = EncodeToDef(HelperLangData["LANG"]["Lang"]);
                        if (tmpstring == LangList.Text)
                        {
                            if (File.Exists("dotahelper.cfg.bak"))
                            {
                                File.Delete("dotahelper.cfg.bak");
                            }
                            if (File.Exists("dotahelper.ini"))
                            {
                                File.Move("dotahelper.ini", "dotahelper.cfg.bak");
                            }
                            if (File.Exists(filescfg[n]))
                            {
                                File.Copy(filescfg[n], "dotahelper.ini");
                            }
                            DotaHelper = new FileIniDataParser();
                            DotaHelperData = DotaHelper.ReadFile("DotaHelper.ini", Encoding.Default);
                            _status_string = _status.Text;
                            this.Width = 340;
                            MiniMap = new Bitmap(MinimapPan1.BackgroundImage, MinimapPan1.BackgroundImage.Width, MinimapPan1.BackgroundImage.Height);
                            Boolean SSREENABLED = false;
                            Boolean.TryParse(DotaHelperData["FEATURES"]["SSRE"], out SSREENABLED);
                            Boolean SKILLENABLED = false;
                            Boolean.TryParse(DotaHelperData["FEATURES"]["SKILL"], out SKILLENABLED);
                            Boolean ENEMYENABLED = false;
                            Boolean.TryParse(DotaHelperData["FEATURES"]["ENEMY"], out ENEMYENABLED);
                            Boolean CHECKVISENABLED = false;
                            Boolean.TryParse(DotaHelperData["FEATURES"]["CHECKVIS"], out CHECKVISENABLED);
                            Boolean CheckMoneyENABLED = false;
                            Boolean.TryParse(DotaHelperData["FEATURES"]["CheckMoney"], out CheckMoneyENABLED);
                            Boolean SSRECHAT = false;
                            Boolean.TryParse(DotaHelperData["ALLCHAT"]["SSRE"], out SSRECHAT);
                            Boolean SKILLCHAT = false;
                            Boolean.TryParse(DotaHelperData["ALLCHAT"]["SKILL"], out SKILLCHAT);
                            Boolean ENEMYCHAT = false;
                            Boolean.TryParse(DotaHelperData["ALLCHAT"]["ENEMY"], out ENEMYCHAT);
                            float EnemyRad = 3000f;
                            var us_EN = new CultureInfo("en-US");
                            EnemyRad = float.Parse(DotaHelperData["SET"]["EnemyDetect"], us_EN);

                            SSRE1.Checked = SSREENABLED;
                            Skills1.Checked = SKILLENABLED;
                            DEnemy1.Checked = ENEMYENABLED;

                            inchat1.Checked = SSRECHAT;
                            inchat2.Checked = SKILLCHAT;
                            inchat3.Checked = ENEMYCHAT;

                            NotifyE1.Checked = CHECKVISENABLED;
                            Guesss1.Checked = CheckMoneyENABLED;

                            distance1.Text = EnemyRad.ToString().Replace(',', '.');

                            distance1.Visible = DEnemy1.Checked;

                            

                            FileIniDataParser ConfigLang = new FileIniDataParser(); ;
                            IniData ConfigLangData = ConfigLang.ReadFile(fileshelp[n], Encoding.UTF8);

                            UpdateCFG1.Text = ConfigLangData["LANG"]["UpdateCFG"];
                            InjectDll1.Text = ConfigLangData["LANG"]["InjectDll"];
                            ForceStart1.Text = ConfigLangData["LANG"]["ForceStart"];
                            SSRE1.Text = ConfigLangData["LANG"]["SSRE"];
                            DEnemy1.Text = ConfigLangData["LANG"]["DEnemy"];
                            Skills1.Text = ConfigLangData["LANG"]["Skills"];
                            inchat1.Text = ConfigLangData["LANG"]["inchat"];
                            inchat2.Text = ConfigLangData["LANG"]["inchat"];
                            inchat3.Text = ConfigLangData["LANG"]["inchat"];
                            NotifyE1.Text = ConfigLangData["LANG"]["NotifyE"];
                            Guesss1.Text = ConfigLangData["LANG"]["Guesss"];
                            AllWrd1.Text = ConfigLangData["LANG"]["AllWrd"];
                            MinesL1.Text = ConfigLangData["LANG"]["MinesL"];
                            Herolist1.Text = ConfigLangData["LANG"]["Herolist"];
                            UnilogB1.Text = ConfigLangData["LANG"]["UnilogB"];
                            ClearBtn1.Text = ConfigLangData["LANG"]["ClearBtn"];
                            MinimapPan1.Text = ConfigLangData["LANG"]["MinimapPan"];
                            Unloader.Text = ConfigLangData["LANG"]["Unloader"];

                            toolTip1.SetToolTip(this.UpdateCFG1, ConfigLangData["LANGTT"]["UpdateCFG"]);
                            toolTip1.SetToolTip(this.InjectDll1, ConfigLangData["LANGTT"]["InjectDll"]);
                            toolTip1.SetToolTip(this.ForceStart1, ConfigLangData["LANGTT"]["ForceStart"]);
                            toolTip1.SetToolTip(this.SSRE1, ConfigLangData["LANGTT"]["SSRE"]);
                            toolTip1.SetToolTip(this.DEnemy1, ConfigLangData["LANGTT"]["DEnemy"]);
                            toolTip1.SetToolTip(this.Skills1, ConfigLangData["LANGTT"]["Skills"]);
                            toolTip1.SetToolTip(this.inchat1, ConfigLangData["LANGTT"]["inchat"]);
                            toolTip1.SetToolTip(this.inchat2, ConfigLangData["LANGTT"]["inchat"]);
                            toolTip1.SetToolTip(this.inchat3, ConfigLangData["LANGTT"]["inchat"]);
                            toolTip1.SetToolTip(this.NotifyE1, ConfigLangData["LANGTT"]["NotifyE"]);
                            toolTip1.SetToolTip(this.Guesss1, ConfigLangData["LANGTT"]["Guesss"]);
                            toolTip1.SetToolTip(this.AllWrd1, ConfigLangData["LANGTT"]["AllWrd"]);
                            toolTip1.SetToolTip(this.MinesL1, ConfigLangData["LANGTT"]["MinesL"]);
                            toolTip1.SetToolTip(this.Herolist1, ConfigLangData["LANGTT"]["Herolist"]);
                            toolTip1.SetToolTip(this.UnilogB1, ConfigLangData["LANGTT"]["UnilogB"]);
                            toolTip1.SetToolTip(this.ClearBtn1, ConfigLangData["LANGTT"]["ClearBtn"]);
                            toolTip1.SetToolTip(this.MinimapPan1, ConfigLangData["LANGTT"]["MinimapPan"]);
                            toolTip1.SetToolTip(this.Unloader, ConfigLangData["LANGTT"]["Unloader"]);
                        }
                    }
                }
            }
        }
    }
}